package com.blog.cloud.comm.webutils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Random;

public class GetWaterId {
	
	
	public static final String  FORMAT_DATE_TIME="yyyyMMdd HH:mm:ss";
	public static final String  FORMAT_DATE="yyyyMMdd";
	
	private static int _suffix = 0;
	private static int _suffix_noSleep = 100;
	
	
	
	
	/**
	 * 
	 * 获取序列号
	 * @return
	 */
	public  static String getSerialId(){
		int radomInt = new Random().nextInt(9999999);
		String currDate = DateUtils.getCurrDate("yyyyMMddSSS");
		return currDate+String.valueOf(radomInt);
	}
	
	public static String formatDate(Date date, String aformat) {
		if (date == null) {
			return "------";
		} else {
			String s1 = "";
			// 设置日期格式
			SimpleDateFormat simpledateformat = new SimpleDateFormat(aformat);
			s1 = simpledateformat.format(date);
			return s1;
		}
	}
	public static synchronized String getWaterId() {
		String strTmp = formatDate(new Date(), "yyyyMMddHHmmssSSS");
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (_suffix > 9) {
			_suffix = 0;
		}
		strTmp = strTmp + _suffix;
		_suffix++;
		return strTmp;
	}


}
